package com.gzu.ltms.entity.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;

import java.io.Serial;

/**
 * 操作日志审计表 表定义层。
 *
 * @author mm
 * @since 2025-05-06
 */
public class OperationLogTableDef extends TableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 操作日志审计表
     */
    public static final OperationLogTableDef OPERATION_LOG = new OperationLogTableDef();

    /**
     * 操作IP
     */
    public final QueryColumn IP = new QueryColumn(this, "ip");

    /**
     * 日志id
     */
    public final QueryColumn LOG_ID = new QueryColumn(this, "log_id");

    /**
     * 操作详情
     */
    public final QueryColumn DETAIL = new QueryColumn(this, "detail");

    /**
     * 操作目标ID
     */
    public final QueryColumn TARGET_ID = new QueryColumn(this, "target_id");

    /**
     * 创建时间
     */
    public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");

    /**
     * 操作人id
     */
    public final QueryColumn OPERATOR_ID = new QueryColumn(this, "operator_id");

    /**
     * 操作类型
     */
    public final QueryColumn OPERATION_TYPE = new QueryColumn(this, "operation_type");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{LOG_ID, OPERATOR_ID, OPERATION_TYPE, TARGET_ID, DETAIL, IP, CREATE_TIME};

    public OperationLogTableDef() {
        super("", "operation_log");
    }

    private OperationLogTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public OperationLogTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new OperationLogTableDef("", "operation_log", alias));
    }

}
